<?php defined( 'BASEPATH' ) or die( 'Restricted' );
/*
This code is Copyright (C) by TMLA INC.  ALL RIGHTS RESERVED.
Please view license.txt in /tgsf_core/legal/license.txt or
http://tgWebSolutions.com/opensource/tgsf/license.txt
for complete licensing information.
*/
//------------------------------------------------------------------------
abstract class tgsfBaseParser extends tgsfBase implements Iterator
{
	protected $_ro_fileName = null;
	protected $_handle = false;
	protected $_open = false;

	//------------------------------------------------------------------------
	/**
	*
	*/
	public function __construct()
	{

        $this->position = 0;
    }
	//------------------------------------------------------------------------
	// must implement for iterator
	//------------------------------------------------------------------------
	function rewind()
	{
		if ( $this->_open )
		{
			$this->_handle->rewind();
		}
	}
	//------------------------------------------------------------------------
	function current()
	{
		if( $this->_open )
		{
			$this->_handle->current();
		}
	}
	//------------------------------------------------------------------------
	function key()
	{
		if ( $this->_open )
		{
			$this->_handle->key();
		}
	}
	//------------------------------------------------------------------------
	function next()
	{
		if ( $this->_open )
		{
			$this->_handle->next();
		}
    }
	//------------------------------------------------------------------------
	function valid()
	{
		if ( $this->_open )
		{
			return $this->_handle->valid();
		}
		return false;
    }
	//------------------------------------------------------------------------
	/**
	* Sets the read-only property for filename.
	*/
	public function &fileName( $fileName )
	{
		$this->_ro_fileName = $fileName;
		return $this;
	}
	//------------------------------------------------------------------------
	/**
	* Sets the buffer of the file based on a string instead of a file name
	* @param String the buffer to use
	*/
	public function &fileBuffer( $buffer )
	{
		return $this->fileName( 'data:text/plain,' . urlencode( $buffer ) );
	}
	//------------------------------------------------------------------------
	/**
	* Open's the stream for parsing
	*/
	public function open()
	{
		$this->_open = true;
		$this->_handle = new SplFileObject( $this->_ro_fileName, 'r' );
	}
}
